#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "MyTaskBarIcon.h"

BEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon)
    EVT_TASKBAR_LEFT_DOWN(MyTaskBarIcon::OnLeftButtonClick)
	EVT_TASKBAR_RIGHT_DOWN(MyTaskBarIcon::OnRightButtonClick)
	EVT_MENU_RANGE(ID_TBI_Show,ID_TBI_Close,MyTaskBarIcon::OnTaskBarMenuClick)

END_EVENT_TABLE()

MyTaskBarIcon::MyTaskBarIcon(wxFrame* parent):wxTaskBarIcon()
{
	this->parent = parent;
}

MyTaskBarIcon::~MyTaskBarIcon()
{

}

void MyTaskBarIcon::OnLeftButtonClick(wxTaskBarIconEvent &event)
{
	if (parent->IsShown())
		parent->Hide();
	else
		parent->Show();
	event.Skip();
}

void MyTaskBarIcon::OnRightButtonClick(wxTaskBarIconEvent& event){
	TaskBarIconContextMenu menu(this);
	PopupMenu(&menu);
	event.Skip();
}


void MyTaskBarIcon::OnTaskBarMenuClick(wxCommandEvent& event){
	int id = event.GetId();
	switch(id){
	case ID_TBI_Show:
		parent->Hide();
		break;
	case ID_TBI_Hide:
		parent->Show();
		break;
	case ID_TBI_About:
		wxMessageBox(ABOUT,_T("About"));
		break;
	case ID_TBI_Close:
		parent->Destroy();
		break;
	}
	event.Skip();
}

TaskBarIconContextMenu::TaskBarIconContextMenu(MyTaskBarIcon* taskBarIcon){
	this->taskBarIcon = taskBarIcon;
	wxFrame* frame = (wxFrame*)taskBarIcon->GetParentFrame();
	if ( frame->IsShown() )
		Append(ID_TBI_Show, wxT("&Hide"));
	else
		Append(ID_TBI_Hide, wxT("&Show"));
	Append(ID_TBI_About, wxT("&About"));
	Append(ID_TBI_Close, wxT("&Close"));
}